package it.unisa.dao.implementation;

import java.util.List;

import it.unisa.beans.Account;
import it.unisa.beans.Petroglyph;
import it.unisa.dao.PetroglyphDao;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

public class PetroglyphHibernateDao extends HibernateDaoSupport implements
		PetroglyphDao {

	public void insert(Petroglyph petroglyph) {
		getHibernateTemplate().saveOrUpdate(petroglyph);

	}

	public void update(Petroglyph petroglyph) {
		getHibernateTemplate().saveOrUpdate(petroglyph);

	}

	public void delete(int id) {
		Petroglyph petroglyph=new Petroglyph();
		petroglyph.setId(id);
		getHibernateTemplate().delete(petroglyph);
	}

	public List<Petroglyph> find(Petroglyph petroglyph) {
		DetachedCriteria criteria = DetachedCriteria.forClass(Petroglyph.class);
		
		if(petroglyph.getId()!=0)
			criteria.add(Restrictions.eq("id", petroglyph.getId()));
		
		return(List<Petroglyph>) getHibernateTemplate().findByCriteria(criteria);
		
	}

	public List<Petroglyph> findAllPetroglyphs() {
		return getHibernateTemplate().find("from Petroglyph");

	}

	public int petroglyphCount() {
		return findAllPetroglyphs().size();
	}

	
}
